package vashion.azeroth.common.common.check;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FormatCheck {

	/**
	 * 验证手机号  
	 * @param str
	 * @return
	 */
	public static boolean isMobile(String str) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1][0-9]{10}$");
        m = p.matcher(str);
        b = m.matches();
        return b;  
    }
	
	/**
	 * 验证电话号码
	 * @param str
	 * @return
	 */
    public static boolean isPhone(String str) {
        Pattern p1 = null,p2 = null;
        Matcher m = null;  
        boolean b = false;
        p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$");  // 验证带区号的  
        p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$");         // 验证没有区号的  
        if(str.length() >9)  {
        	m = p1.matcher(str);
            b = m.matches();
        } else {
            m = p2.matcher(str);
            b = m.matches();
        }
        return b;
    }
    
	/**
	 * 验证数字
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str){
		return str.matches("^\\d+$");
	}
    
    /**
     * 验证两位小数
     * @param str
     * @return
     */
    public static boolean isNumber(String str) {
        return str.matches("\\d+\\.\\d{1,2}$");
    }
    
    /**
     * 验证是否是合法金额
     * @param str
     * @return
     */
    public static boolean isLegalAmount(String str) {
    	return isNumeric(str) || isNumber(str);
    }
    
    /**
     * 验证是否是合法的密码
     * @param str
     * @return
     */
    public static boolean isLegalPassword(String str) {
    	return str.matches("^[a-zA-Z_0-9]{6,18}$");
    }
    
    public static void main(String[] args) {
    	String s = "0.01";
    	System.out.println(isLegalAmount(s));
    }
      
}
